package com.beilang.hotline.knowledge.page;

import com.beilang.base.codelookup.manager.CodeLookupMgr;
import com.beilang.base.core.page.BasePage;
import com.beilang.base.pagination.PaginationHelper;
import com.beilang.base.util.CodeConstant;
import com.beilang.base.util.DateUtil;
import com.beilang.hotline.knowledge.manager.KnowledgeMgr;
import com.beilang.hotline.knowledge.model.KnowledgeModel;
import com.beilang.hotline.knowledge.to.SearchTO;
import com.beilang.hotline.user.model.UserModel;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@SuppressWarnings("unchecked")
public class KnowledgePage extends BasePage{

	private CodeLookupMgr codeLookupMgr;

	private KnowledgeMgr knowledgeMgr;

	public void setKnowledgeMgr(KnowledgeMgr knowledgeMgr) {
		this.knowledgeMgr = knowledgeMgr;
	}

	public void setCodeLookupMgr(CodeLookupMgr codeLookupMgr) {
		this.codeLookupMgr = codeLookupMgr;
	}

	public List getSysList(){
		List list=new ArrayList();
		list.add(this.getEmptyIntCodeModel());
		list.addAll(getAddSysList());
		return list;
	}

	public List getAddSysList(){
		 return codeLookupMgr.getCodeListWithFilter(CodeConstant.SYS_NAME, CodeConstant.CODE_FILTER, new ArrayList());
	}

	public List getUpdateSysList(){
		 return getAddSysList();
	}

    public PaginationHelper getSearchList(PaginationHelper helper,SearchTO searchTO){
		helper=knowledgeMgr.getKnowledgeList(helper, searchTO);
		return helper;
	}

	public PaginationHelper deleteKnowledgeList(PaginationHelper helper,SearchTO searchTO,List deleteList){
        for (Object obj : deleteList) {
            KnowledgeModel knowledgeModel = (KnowledgeModel) obj;
            knowledgeMgr.deleteKnowledge(knowledgeModel.getKnowledgeId());
        }
		return this.getSearchList(helper, searchTO);
	}

	public KnowledgeModel addKnowledge(KnowledgeModel knowledgeModel){
		UserModel user=this.getLoginUser();
		knowledgeModel.setCreateId(user.getUserId());
		knowledgeModel.setUpdateId(user.getUserId());
		Date date = DateUtil.getDate();
		knowledgeModel.setCreateTime(date);
		knowledgeModel.setUpdateTime(date);
		knowledgeModel=knowledgeMgr.createKnowledge(knowledgeModel);
		return knowledgeModel;
	}

	public KnowledgeModel getViewKnowledge(Long knowledgeId){
		return knowledgeMgr.getKnowledge(knowledgeId);
	}

	public KnowledgeModel getUpdateKnowledge(Long knowledgeId){
		return getViewKnowledge(knowledgeId);
	}

	public KnowledgeModel updateKnowledge(KnowledgeModel knowledgeModel){
		UserModel user=this.getLoginUser();
		knowledgeModel.setUpdateId(user.getUserId());
		Date date = DateUtil.getDate();
		knowledgeModel.setUpdateTime(date);
		knowledgeModel=knowledgeMgr.saveKnowledge(knowledgeModel);
		return knowledgeModel;
	}



}
